<template>
  <div class="IPimage" v-if="getId() == 615265577537605" @click="audioPlay">
    <div class="IPBox">
      <div class="tooltip-conetnt" :style="store.isMobileType && { opacity: '1' }">
        <div class="popup__arrow-parent">
          <div class="t-popup__arrow"></div>
        </div>
        <span>点击播放语音讲解</span>
      </div>
      <img :src="publicUrls + 'free/style11/IP.png'" alt="" class="IPImg" />
      <img :src="publicUrls + 'free/style11/IPhand.png'" alt="" class="IPhand" />
    </div>
  </div>
</template>

<script lang="ts">
export default defineComponent({
  name: 'IpImage',
});
</script>

<script lang="ts" setup>
import { useProjectStore } from '@/store';
import getId from '@/utils/getId';
import { publicUrls } from '@/utils/minxin';
import { defineComponent, ref, watch } from 'vue';

const props = defineProps({
  index: {
    type: Number,
    default: 0,
  },
  url: {
    type: String,
    default: '',
  },
});

const audioRef = ref(null);
const store = useProjectStore();

const audioPlay = () => {
  if (store.style11Audio instanceof Audio && getId() == 615265577537605) {
    if (
      store.style11Audio.src ===
      `https://static.jiyi.show/free/style11/${props.index === 0 ? props.index : props.index + 1}.mp3`
    ) {
      store.style11Audio.pause();
      store.style11Audio = null;
      return;
    }
    store.style11Audio.pause();
    store.style11Audio = new Audio(
      `https://static.jiyi.show/free/style11/${props.index === 0 ? props.index : props.index + 1}.mp3`,
    );
    store.style11Audio.play();
  } else if (getId() == 615265577537605) {
    store.style11Audio = new Audio(
      `https://static.jiyi.show/free/style11/${props.index === 0 ? props.index : props.index + 1}.mp3`,
    );
    store.style11Audio.play();
  }
};
</script>

<style scoped lang="less" >
.IPimage {
  width: 125px;
  height: 120px;
  position: absolute;
  bottom: 0;
  right: -80px;
  z-index: 666;
  // animation: ip-anim 3s linear infinite;
  .IPBox {
    width: 100%;
    height: 100%;
    position: relative;
    .IPImg {
      width: 125px;
      height: 121px;
    }
    .IPhand {
      width: 43px;
      height: 46px;
      position: absolute;
      left: -34px;
      top: 50%;
      transform-origin: right center;
      animation: ip-rotate 2s linear infinite;
    }
    &:hover > .tooltip-conetnt {
      opacity: 1;
    }
    .tooltip-conetnt {
      opacity: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      // justify-content: center;
      position: absolute;
      left: 50%;
      top: -40px;
      transform: translateX(-50%);
      width: 149px;
      height: 24px;
      margin: 2px 0;
      background: #546f7f;
      box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.25);
      border-radius: 4px;
      span {
        font-family: Microsoft YaHei;
        font-size: 13px;
        font-weight: 400;
        line-height: 20px;
        text-align: center;
        color: #f1efea;
        margin-top: 2px;
      }
      :deep(.t-popup__arrow) {
        bottom: -3px;
        left: 68.5px;
        // background: rgba(147, 178, 170, 1);
        border-color: #546f7f;
        z-index: -1;
      }
      .t-popup__arrow::before {
        background: #546f7f;
      }
    }
  }
}
@keyframes ip-rotate {
  0% {
    transform: translateY(-50%) rotate(0deg);
  }
  50% {
    transform: translateY(-50%) rotate(20deg);
  }
  100% {
    transform: translateY(-50%) rotate(0deg);
  }
}
</style>